<div id="panel-button" class="row">
	<div class="col-md-12">
		<div class="panel panel-default">
			<div class="panel-body text-right">
				<div class="col-sm-4 pull-left">
					{{Form::text('filter', null, array('id' => 'filter', 'class' => 'form-control', 'placeholder' => trans('form.filter')))}}
				</div>
				<div class="col-sm-8 pull-right">
					{{Form::button(trans('form.back'), array('class' => 'btn btn-default', 'id' => 'cancel'))}}
				</div>
			</div>
		</div>
	</div>
</div>

<div id="panel-button-fixed" class="row hidden">
	<div class="col-md-12">
		<div class="panel panel-default">
			<div class="panel-body text-right">
				<div class="col-sm-4 pull-left">
					{{Form::text('filter', null, array('id' => 'filter', 'class' => 'form-control', 'placeholder' => trans('form.filter')))}}
				</div>
				<div class="col-sm-8 pull-right">
					{{Form::button(trans('form.back'), array('class' => 'btn btn-default', 'id' => 'cancel'))}}
				</div>
			</div>
		</div>
	</div>
</div>

<div class="row">
	<div class="col-md-12">
		<div class="panel panel-default">
			<!--<header class="panel-heading">{{trans('customer.customer_list')}}</header>-->
			<div class="panel-body">
				<div class="table-responsive">
					<table class="table table-striped footable" data-filter="#filter" data-page-size="10" data-filter-minimum="1">
						<thead>
							<tr>
								<th>{{trans('order.date')}}</th>
								<th>{{trans('refund.total')}}</th>
								<th>{{trans('order.order_number')}}</th>
								<th>{{trans('form.delete')}}</th>
							</tr>
						</thead>
						<tbody>
							@foreach($result as $row)
							<?php
								if(isset($row->order) && $row->order > 0){
									$disable = 'disabled = "disabled"';
								}else{
									$disable = "";
								}
							?>
								<tr id="customer" data-id="{{$row->id}}">
									<td>{{date("d-m-Y", strtotime($row->date))}}</td>
									<td>{{MoneyFormat::format($row->total)}}</td>
									<td>{{$row->order}}</td>
									<td style="width: 30px;">{{Form::button(trans('form.delete'), array('id' => 'delete', 'data-id' => $row->id, 'class' => 'btn btn-xs btn-danger', $disable))}}</td>
								</tr>
							@endforeach
						</tbody>
						<tfoot>
							<tr>
								<td colspan="3">
									<ul class="pagination pagination-sm"></ul>
								</td>
							</tr>
						</tfoot>
					</table>
				</div>
			</div>
		</div>
	</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
	$("button#add").click(function(){
		var id = $(this).attr('data-id');
		var url = '{{URL::to("admin/refund/create/")}}' + "/" + id;

		window.location = url;
	});

	$("button#delete").click(function(){
		var ok = confirm('{{trans('refund.confirm_delete')}}');

		if(ok){
			var id = $(this).attr('data-id');
			
			$.ajax({
				url: '{{URL::to("admin/refund/delete/")}}',
				type: 'POST',
				data: {'id': id},
				beforeSend: ajaxLoading(),
				success: function(result){
					var rs = $.parseJSON(result);

					if(rs.error == false){
						window.location.reload();
					}else{
						appendErrorMessages(rs.message);
					}

					ajaxLoadSuccess();
				}
			});
		}
	});

	$("button#cancel").click(function(){
		var url = "{{URL::to('/admin/refund/')}}";

		window.location = url;
	});

	$('.footable').footable();
});
</script>